﻿using LuDragon.Data.Entities;
using LuDragon.IService.System;
using System;
using System.Collections.Generic;
using System.Linq;

namespace LuDragon.Service.System
{
    public class RoleSerivce : BaseService<Sys_Role>, IRoleService
    {
        /// <summary>
        /// 获取角色实体
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public Sys_Role GetRole(int roleId)
        {
            return GetModel(a => a.RoleId == roleId);
        }
        /// <summary>
        /// 获取角色列表
        /// </summary>
        /// <returns></returns>
        public List<Sys_Role> GetRoleList()
        {
            return GetAll().ToList();
        }
        /// <summary>
        /// 保存角色
        /// </summary>
        /// <returns></returns>
        public Sys_Role SaveRole(Sys_Role model)
        {
            if (model == null)
            {
                throw new Exception("实体参数为Null");
            }
            if (model.RoleId > 0)
            {
                Update(model);
                return model;
            }
            else
            {
                return Add(model);
            }
        }
        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DelRole(int id)
        {
            return Delete(GetModel(a => a.RoleId == id));
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool DelRole(Sys_Role model)
        {
            return Delete(model);
        }
    }
}
